﻿using B.R.RabbitRoot.Domain.animal_husbandry;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Write.API.Applications.Commands.HealthCareCommands;
using MediatR;

namespace B.R.RabbitRoot.Write.API.Applications.Commandhandlers.HealthCareCommandHandler
{
    /// <summary>
    ///  修改健康信息命令
    /// </summary>
    public class HealthCareUpdateCommandHandler : IRequestHandler<HealthCareUpdateCommand, APIResult<int>>
    {
        private readonly IBaserepository<HealthCareInfo> _healthCareInfo;

        public HealthCareUpdateCommandHandler(IBaserepository<HealthCareInfo> healthCareInfo)
        {
            _healthCareInfo = healthCareInfo;
        }

        public async Task<APIResult<int>> Handle(HealthCareUpdateCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result=new APIResult<int>();
            var entity = await _healthCareInfo.UpdateAsync(new HealthCareInfo {
                FarmingDetailsId=request.FarmingDetailsId,
                HealthCareInfoId=request.HealthCareInfoId,
                FeedingDays=request.FeedingDays,
                HealthCareMethod=request.HealthCareMethod,
                HealthCareProcedure=request.HealthCareProcedure,
            });
            return await Task.FromResult(result.Success(entity));
        }
    }
}
